// import { buriedPoint } from '@/api/marketing'

/**
 * 获取url参数
 * @param name 参数名
 */
export function getUrlParam(name: string) {
  const url = window.location.href;
    name = name.replace(/[$$$$]/g, "\\$&");
    const regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)");
    const results = regex.exec(url);
    console.log(regex)
    console.log(results)
    if (!results) {
        return null;
    }
    if (!results[2]) {
        return '';
    }
    return decodeURIComponent(results[2].replace(/\+/g, " "));
}

/**
 * 分隔金额
 * @param amount
 * @returns amount
 */
export function splitAmount(amount: number) {
  return amount.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')
}

/**
 * 获取登录平台
 * @returns IOS/Android/Web
 */
export function getLoginPlatform() {
  const u = navigator.userAgent
  const isAndroid = u.includes('Android') || u.includes('Adr')
  const isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)
  return isAndroid ? 'Android' : isiOS ? 'iOS' : 'Web'
}

/**
 * 号码隐藏中间四位
 * @param phone 电话号码
 * @returns phone
 */
export function hidePhone(phone: string) {
  return phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2')
}

/**
 * 埋点
 * @param buried 埋点枚举
 */
// export function handlerBuriedPoint(buried: string) {
//   buriedPoint({ buried })
// }

/**
 * 处理金额，大于一万显示万元
 * @param amount 单位元
 * @returns amount
 */
export function handlerAmountToThousand(amount: number) {
  if (amount > 10000)
    return `${(amount / 10000).toFixed(2)}`
  return amount
}
